/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.diamondsys.embrapa;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Pablo
 */
@Stateless
public class VisitasFacade extends AbstractFacade<Visitas> {
    @PersistenceContext(unitName = "com.diamondsys_embrapa_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public VisitasFacade() {
        super(Visitas.class);
    }
    
    public List<Visitas> findByClienteId(TbInst clienteId) {
        
        return em.createQuery("SELECT v FROM Visitas v WHERE v.tbInstCodInstituicao = :tbInstCodInstituicao", Visitas.class)
                .setParameter("tbInstCodInstituicao", clienteId)
                .getResultList();
    }
 
    public List<Visitas> findAbertasByClienteId(TbInst clienteId) {
        
        return em.createQuery("SELECT v FROM Visitas v WHERE v.tbInstCodInstituicao = :tbInstCodInstituicao AND v.dataSaida is null", Visitas.class)
                .setParameter("tbInstCodInstituicao", clienteId)
                .getResultList();
    }
    
}
